#ifndef TCPCONN_HH_
#define TCPCONN_HH_
#include"eventpool.hh"
#include"socket.hh"
#include"InetAddr.hh"
#include"socketio.hh"
#include<functional>
#include<string>
#include<memory>

using std::function;
using std::string;
using std::shared_ptr;

class TcpConnection
:public std::enable_shared_from_this<TcpConnection>
{
public:

    using Tcpconptr=shared_ptr<TcpConnection>;
using func_call=function<void(const Tcpconptr&)>;
   explicit TcpConnection(int fd,Eventpool* rhs);

    ~TcpConnection();

   void send(string msg);

   string recv();

   void SetCloseCallback(func_call&& rhs);
   void SetNewconnCallback(func_call&& rhs);
   void SetNewMsgCallback(func_call&& rhs);

   void handleClosecall();
   void handleConncall();
   void handleMsgcall();
   string to_string();

   void sendinpoll(string msg);

   bool is_closed() const ;
   

private:
   //获取地址
   InetAddr getlocaladdr();
   InetAddr getpeeraddr();



private:
    Socket _sock;
    SockIo _io;
    InetAddr _localaddr;
    InetAddr _peeraddr;
    func_call _onclose;
    func_call _onmsg;
    func_call _onnewconn;
    Eventpool* _event;
};
#endif
